from queue import Queue
from threading import Thread
from time import sleep


def produce():
    num = 1
    while True:
        if q.qsize() > 5:
            print(f'缓冲区已满，请先消费库存')
            continue
        print(f'生产{num}号产品')
        q.put(f'{num}号产品')
        sleep(1)
        num += 1


def consume():
    while True:
        print(f'当前消耗了{q.get()}')
        sleep(3)


if __name__ == '__main__':
    q = Queue()
    pro = Thread(target=produce)
    c1 = Thread(target=consume)
    c2 = Thread(target=consume)
    pro.start()
    c1.start()
    c2.start()